<?php
/**
 * Created by PhpStorm.
 * User: lzy
 * Date: 2019/6/12
 * Time: 15:50
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IUser;
use App\Http\Requests\Admin\UserInputDTO;
use App\Http\Requests\Admin\UserRoleInputDTO;
use App\Util\LayUiVo;
use App\Util\ResultsVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class UserController extends Controller
{
    public $userService;

    public function __construct(IUser $userService)
    {
        $this->userService = $userService;
    }

    public function page(Request $request){
        $search = [];
        if ($request->get('nickname')) {
            $search['nickname'] = $request->get('nickname');
        }
        if ($request->get('username')) {
            $search['username'] = $request->get('username');
        }
        $dao = $this->userService->lists($search, $request->get('page', 1), $request->get('limit','10'));
        return response()->json(new LayUiVo(['data'=>$dao,'message'=>Lang::get('response.success')]));
    }

    public function store(UserInputDTO $inputDTO){
        $this->userService->store($inputDTO);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

    public function update(UserInputDTO $inputDTO,$id){
        $this->userService->update($inputDTO,$id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

    public function job($id,$state){
        $this->userService->job($id,$state);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

    public function role(UserRoleInputDTO $inputDTO,$id){
        $this->userService->role($inputDTO,$id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

}